package com.example.chcrm.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.chcrm.entity.common.ResponseMsg;
import com.example.chcrm.entity.common.ServletUtils;
import com.example.chcrm.entity.consignor.CustomerCarBrand;
import com.example.chcrm.entity.employee.Department;
import com.example.chcrm.entity.employee.EmployeeVo;
import com.example.chcrm.service.CustomerCarBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author 邹
 * @Date 2025/4/20 17:36
 * @Version 1.0
 */
@RestController
@RequestMapping("/sys/customerBrand")
@CrossOrigin // 允许跨域访问
public class CustomerCarBrandController {
    
    @Autowired
    private CustomerCarBrandService customerCarBrandService;

    /**
     * 分页查询
     */
    @PostMapping("/pageList")
    public ResponseMsg<IPage<CustomerCarBrand>> pageList(@RequestBody CustomerCarBrand customerCarBrand) {
        //获取登录用户信息
        HttpServletRequest request = ServletUtils.getRequest();
        EmployeeVo empVo = request != null ? (EmployeeVo) request.getAttribute("empVo") : null;
        return customerCarBrandService.pageList(customerCarBrand, empVo);
    }

    /**
     * 获取品牌详情
     */
    @GetMapping("/detail/{id}")
    public ResponseMsg<Object> detail(@PathVariable String id) {
        HttpServletRequest request = ServletUtils.getRequest();
        EmployeeVo empVo = request != null ? (EmployeeVo) request.getAttribute("empVo") : null;
        return customerCarBrandService.detail(id);
    }

    /**
     * 修改品牌信息
     */
    @PostMapping("/update")
    public ResponseMsg<Object> update(@RequestBody CustomerCarBrand customerCarBrand) {
        HttpServletRequest request = ServletUtils.getRequest();
        EmployeeVo empVo = request != null ? (EmployeeVo) request.getAttribute("empVo") : null;
        return customerCarBrandService.update(customerCarBrand, empVo);
    }

    /**
     * 禁用/启用品牌
     */
    @PostMapping("/disable")
    public ResponseMsg<Object> disable(@RequestBody CustomerCarBrand customerCarBrand) {
        HttpServletRequest request = ServletUtils.getRequest();
        EmployeeVo empVo = request != null ? (EmployeeVo) request.getAttribute("empVo") : null;
        return customerCarBrandService.disable(customerCarBrand, empVo);
    }

    /**
     * 新增
     */
    @PostMapping("/add")
    public ResponseMsg<Object> add(@RequestBody CustomerCarBrand department) {
        HttpServletRequest request = ServletUtils.getRequest();
        EmployeeVo empVo = request != null ? (EmployeeVo) request.getAttribute("empVo") : null;
        return  customerCarBrandService.add(department,empVo);
    }

    @GetMapping("/selectAllBrand")
    public ResponseMsg<Object> pageList() {
        return customerCarBrandService.selectAllBrand();
    }
}
